import os
import sys
import copy
import codecs
import mimetypes
import getopt
import string
from os import path
from PyQt4 import Qt
import smtplib
import mimetypes
import linecache
from __ob import *
from email import Encoders
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart

def cartel_p_rec(dir_cartellini_cli, part_nome, ext):

    files = os.listdir(dir_cartellini_cli)
    files = filter(lambda x: x.find(part_nome) > -1, files)
    files = filter(lambda x: x.find(ext) > -1, files)
    name_n_timestamp = dict([(x, os.stat(dir_cartellini_cli+x).st_mtime) for x in files])
    return dir_cartellini_cli+max(name_n_timestamp, key=lambda k: name_n_timestamp.get(k))


class EmailApplication(Qt.QApplication):
 
    def __init__(self, args):
        """ In the constructor we're doing everything to get our application
            started, which is basically constructing a basic QApplication by 
            its __init__ method, then adding our widgets and finally starting 
            the exec_loop."""
        Qt.QApplication.__init__(self, args)
        self.addWidgets()
        self.exec_()        
 
    def addWidgets(self):
        """ In this method, we're adding widgets and connecting signals from 
            these widgets to methods of our class, the so-called "slots" 
        """
        self.hellobutton = Qt.QPushButton("Say 'Hello world!'",None)
        self.connect(self.hellobutton, Qt.SIGNAL("clicked()"), self.slotSayHello)
        self.hellobutton.show()
 
    def slotSayHello(self):
        """ This is an example slot, a method that gets called when a signal is 
            emitted """
        print "Hello, World!"

    
                